//
//  TableTreeViewController.m
//  SourceCodeRead
//
//  Created by Kael on 2018/2/11.
//  Copyright © 2018年 Kael. All rights reserved.
//

#import "TableTreeViewController.h"

#import "KLTreeView.h"

#import "LXTreeView.h"

@interface TableTreeViewController ()

@property (nonatomic, strong) KLTreeView *treeView;

@property (nonatomic, strong) LXTreeView *lxtreeView;


@property (nonatomic, strong) NSMutableArray *dataSource;


@property (nonatomic, strong) NSDictionary *resultData;


@end

@implementation TableTreeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initBaseData];
    [self initBaseView];

}

#pragma mark - **************** 初始化操作
- (void)initBaseData {
//    NSData *lexueData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"lexue" ofType:@"json"]];
//    NSDictionary *result = [NSJSONSerialization JSONObjectWithData:lexueData options:NSJSONReadingAllowFragments error:nil];
//    _resultData =  [NSDictionary dictionaryWithDictionary:result];
//    _dataSource = [NSMutableArray arrayWithArray:[_resultData objectForKey:@"rpbd"]];
    
    NSData *treeData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tree" ofType:@"json"]];
    NSArray *treeArr = [NSJSONSerialization JSONObjectWithData:treeData options:NSJSONReadingAllowFragments error:nil];
    _dataSource = [NSMutableArray arrayWithArray:treeArr];
}

- (void)initBaseView {
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    [self loadLXTreeView];
}

-(void)loadLXTreeView{
    _lxtreeView = [[LXTreeView alloc]init];
    _lxtreeView.frame = self.view.bounds;
    _lxtreeView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_lxtreeView];
    
    _lxtreeView.dataSource = _dataSource;
    [_lxtreeView.tableView reloadData];
}

-(void)loadKLTreeView{
    _treeView = [[KLTreeView alloc] initWithDataSource:_dataSource];
    _treeView.frame = CGRectMake(0, 64, 414, 736-64);
    _treeView.backgroundColor = [UIColor colorWithRed:0.60 green:0.85 blue:0.53 alpha:1.00];
    [self.view addSubview:_treeView];

}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    NSLog(@"viewDidDisappear");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
